<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      width: 300px;
      height: 40px;
      background-color: rgb(215, 166, 166);
      margin-top: 10px;
    }
  </style>
</head>
<body>
  <div id="app">
    <input type="text" v-model="inputTxt">
    {{ inputTxt }}
    <hr>
    <button @click="addArr">数组新增</button>
    <ul>
      <li v-for="(item, index) in arr" @click="changeLi(index)" :key="index">
        {{ item }}
      </li>
    </ul>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        inputTxt: '你好世界',
        arr: [1,2,3,4]
      },
      methods: {
        changeLi(index){
          this.$set(this.arr, index, '值改变了')
        },
        addArr(){
          this.arr.push(this.arr.length+1);
        }
      },
      // config新增watch属性
      watch: {
        // 简单侦听器
        inputTxt(newVal, oldVal){
          console.log('inputTxt改变了新值是', newVal);
        },
        arr(newVal){
          console.log('arr改变了', newVal);
        }
      }
    })
  </script>
</body>
</html>